package thread;

import socket.ChessServer;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 服务器等待客户端连接线程.
 *
 * @author john
 */
public class WaitClientConnectThread extends Thread {
    private ServerSocket server = null;

    public WaitClientConnectThread(ServerSocket server) {
        this.server = server;
    }

    public void run() {
        try {
            while (true) {
                Socket client = server.accept();
                System.out.println(client + "成功连接服务器");
                ClientAtServerThread cct = new ClientAtServerThread(client);
                ChessServer.getInstance().clientAtServerThreadList.add(cct);
                cct.start();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
